// Object.create()方法创建一个新对象，使用现有的对象来提供新创建的对象的__proto__。
function Animal (name) {
  this.name = name
}

Object.create1 = function (proto, propertyObject = undefined) {
  if (typeof proto !== 'object' && typeof proto !== 'function') {
    // 如果传入的第一个对象不是object 不是 function 就报错
    throw new TypeError('Object prototype may only be an Object or null.')
  }
  if (propertyObject == null) {
    // 如果传入的第二个地下是null 也要报错
    new TypeError('Cannot convert undefined or null to object')
  }
  let obj = {}
  obj.__proto__ = proto
  if (propertyObject !== undefined) {
    Object.defineProperties(obj, propertyObject)
  }
  return obj
}
Object.create2 = function (proto, propertyObject = undefined) {
  // function F () { }
  // F.prototype = proto
  // return new F()
  function F () { }
  F.prototype = proto
  return new F()
}
function Dog () {

}
Dog.prototype.nihao = function () {
  console.log('你好');
}
Animal.prototype.say = function () {
  console.log(1);
}
let dog = new Dog()
dog.__proto__ = Object.create(Animal.prototype, {
  'name': {
    value: '你好'
  },
  'age': {
    value: 30
  }
})
console.log(dog.__proto__ === Animal.prototype);
dog.say()
console.log(dog.age);
